﻿using EnetaMvc.Core.Domain;
using EnetaMvc.Core.Domain.Content;
using EnetaMvc.Core.Repositories;
using EnetaMvc.Infrastructure;
using NHibernate;
using NHibernate.Criterion;

namespace EnetaMvc.Data.NHibernate.Repositories
{
    public class TooltipRepository : BaseRepository, ITooltipRepository
    {
        private readonly ISession _session;

        public TooltipRepository(IMapperSession session) : base(((NHSession)session).GetCurrentSession())
        {
            _session = ((NHSession)session).GetCurrentSession();
        }

        public Tooltip GetTooltipByName(string name)
        {
            var criteria = _session.CreateCriteria<Tooltip>()
                                   .Add(Expression.Eq("Name", name))
                                   .SetMaxResults(1);

            return criteria.UniqueResult<Tooltip>();
        }
    }
}
